#include<bits/stdc++.h>
using namespace std;
#define xyf main
#define maxn 20005

int m,n,dp[maxn],weight;
int xyf()
{
	cin>>m>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>weight;
		for(int j=m;j>=weight;--j)
			dp[j]=max(dp[j],dp[j-weight]+weight);
	}
	cout<<m-dp[m]<<endl;
	return 0;
}
